package td.td1;

import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import tools.FrenchStemmer;
import tools.FrenchTokenizer;
import tools.Normalizer;
import tools.TreeTaggerNormalizer;

/**
 * Solutions du TD 1
 * @author xtannier
 *
 */
public class TD1 {
	/**
	 * Le répertoire du corpus
	 */
	// CHEMIN A CHANGER
	private static String DIRNAME = "/home/xtannier/data/lemonde/";
	/**
	 * Un fichier de ce répertoire
	 */
	private static String FILENAME = DIRNAME + "texte.95-1.txt";
	/**
	 * L'exécutable de TreeTagger
	 */
	// CHEMIN A CHANGER
	private static String TREETAGGER_BIN = "/home/xtannier/tools/TreeTagger/cmd/tree-tagger-french";

	private static DecimalFormat df;
	
	static {
		df = new DecimalFormat("#.#######");
		DecimalFormatSymbols dcmlFS = new DecimalFormatSymbols();
		dcmlFS.setDecimalSeparator('.');
		df.setDecimalFormatSymbols(dcmlFS);
	}
	private static void exo221(String fileName , Normalizer normalizer)
	{
		HashMap<String,String> hits=new HashMap<String,String>();
		
		//segmente le texte
		//parcout le text mot par mot
		//si le mot n'existe pas dans
		// la HashMap,on l;ajoute avec
		//une occurrence
		//s'il existe on incremente le nb
		
	}
	//TD2 2.1
	private static HashMap<String,Integer> getDocumentFrequency(String dirName,Normalizer norm,boolean sw) {
		
		File dir = new File(dirName);
		HashMap<String,Integer> hits= new HashMap<String,Integer>();
		ArrayList<String> wordsInFile;
		ArrayList<String> words;
		String wordLc;
		Integer number;
		if(dir.isDirectory())
		{
			String [] fileNames = dir.list();
			for(String fileName:fileNames)
			{
				wordsInFile=new ArrayList<String>();
				words = norm.normalize(dirName+File.separator+fileName,sw);
				
				for(String word:words)
				{
					wordLc=word;
					wordLc=wordLc.toLowerCase();
					if(!wordsInFile.contains(wordLc))
					{
						number = hits.get(wordLc);
						if(number==null)
						{
							hits.put(wordLc, 1);
						}else{
							hits.put(wordLc, number+1);
						}
					}
					wordsInFile.add(wordLc);
				}
				
			}
		}	
		
		return hits;
	
	
	}

	
	public static void main(String [] args)
	{
		String fileName="texte.95-1.txt";
		Normalizer tokenizer1 = new FrenchTokenizer();
		Normalizer tokenizer2 = new FrenchStemmer();
		Normalizer tokenizer3 = new TreeTaggerNormalizer("chemin vers l'executable ...");
		
		try {
			ArrayList<String> list1 = tokenizer1.normalize(fileName);
			System.out.println(list1);
			
			System.out.println("-----------------------------------------------------------");
			
			ArrayList<String> list2 = tokenizer2.normalize(fileName);
			System.out.println(list2);
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
}
